package com.base.controller;

import com.beust.jcommander.internal.Lists;
import com.base.comm.CommContent;
import com.base.comm.CommExcel;
import com.base.comm.CommUrls;
import com.base.po.param.NetState;
import com.base.po.sqlparam.RechargeablecardsExamplePage;
import com.base.po.voip.Freeroutes;
import com.base.po.voip.FreeroutesExample;
import com.base.po.voip.Rechargeablecards;
import com.base.po.voip.RechargeablecardsExample.Criteria;
import com.base.po.voip.Users;
import com.base.service.*;
import com.base.utils.IP;
import com.base.utils.Page;
import com.base.utils.PasswordUtils;
import com.base.utils.Produce;
import lombok.extern.log4j.Log4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.sql.*;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * admin管理系统控制器
 *
 * @author Rechargeablecards
 */
@Log4j
@Controller
@RequestMapping("/admin")
public class content_chongzhikaguanli {
    @Autowired
    private RechargeablecardsService rechargeablecardsService;
    @Autowired
    private RechargeablecardsGiftService rechargeablecardsGiftService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private LogsService logsService;// log日志
    @Autowired
    private FreeroutesService freeroutesService;
    //读取配置文件
    @Value("${system.file-path}")
    private String filePath;

    @RequestMapping(value = "/doSplitCards",produces = "application/json;charset=utf-8")
    public @ResponseBody
    String doSplitCards(String cardnoFrom, String cardnoTo, String batch, String parentid) {
        if (cardnoFrom == null || cardnoFrom.equals("") || cardnoTo == null || cardnoTo.equals("") || batch == null || batch.equals("")) {
            return "卡号段,批次号必须填写";
        }
        Users users = usersService.selectByUsername(parentid);
        if (users == null) {
            return "无法查询到用户";
        }
        if (Produce.isNumeric(cardnoFrom) && Produce.isNumeric(cardnoTo) && Produce.isNumeric(batch)){
            int i = rechargeablecardsService.updateBatchAndCardsBetween(batch, cardnoFrom, cardnoTo, users.getId());
            if (i > 0) {
                return "更新结束,共更新"+i+"条";
            }
        }

        return "请输入正确的数字";
    }

    @RequestMapping("/updateCardsBySplitStr")
    public @ResponseBody
    NetState updateCardsBySplitStr(HttpServletRequest request,String strs,String shopName){
        if (StringUtils.isEmpty(strs)){
            return new NetState(NetState.FEAILED,"划拨的字符不存在");
        }
       Users users= usersService.selectByUsername(shopName);
        if (users==null){
            return new NetState(NetState.FEAILED,"被划拨代理商不存在");
        }
        Integer count=0;
        log.warn("[逗号划卡]"+strs+"[商户名]"+shopName);
        try{
            String[] strings=strs.split(",");
            for (int i = 0; i < strings.length; i++) {
                String cardsNo=strings[i].trim();
                if (!StringUtils.isEmpty(cardsNo) && !cardsNo.equals(",") ){
                   List<Rechargeablecards> rechargeablecards=rechargeablecardsService.selectByCardNo(cardsNo);
                   if (rechargeablecards.size()>0){
                      Rechargeablecards up= rechargeablecards.get(0);
                       if (up!=null){
                           up.setParentid(users.getId());
                           rechargeablecardsService.updateByPrimaryKeySelective(up);
                           count++;
                       }
                   }
                }
            }
        }catch (Exception e){
            log.warn("[卡密管理报错:]"+e);
            return new NetState(NetState.FEAILED,"划拨出错");
        }
        return new NetState(NetState.SUCCESS_CONN,"划拨成功共划拨："+count+"张");
    }
    @RequestMapping("/updateCardsDateTimeBySplitStr")
    public @ResponseBody
    NetState updateCardsDateTimeBySplitStr(HttpServletRequest request,String strs,Integer dateTime){
        if (StringUtils.isEmpty(strs)){
            return new NetState(NetState.FEAILED,"划拨的字符不存在");
        }
//        Users users= usersService.selectByUsername(shopName);
//        if (date)
        if (dateTime==null || dateTime == 0 ){
            return new NetState(NetState.FEAILED,"修改的时间不正确");
        }
        Integer count=0;
        log.warn("[逗号修改卡]"+strs+"[修改时间]"+dateTime);
        try{
            String[] strings=strs.split(",");
            for (int i = 0; i < strings.length; i++) {
                String cardsNo=strings[i].trim();
                if (!StringUtils.isEmpty(cardsNo) && !cardsNo.equals(",") ){
                    List<Rechargeablecards> rechargeablecards=rechargeablecardsService.selectByCardNo(cardsNo);
                    if (rechargeablecards.size()>0){
                        Rechargeablecards up= rechargeablecards.get(0);
                        if (up!=null){
//                            up.setTermofvalidity(dateTime);
                            up.setProbationperiod(dateTime);
                            rechargeablecardsService.updateByPrimaryKeySelective(up);
                            count++;
                        }
                    }
                }
            }
        }catch (Exception e){
            log.warn("[卡密管理报错:]"+e);
            return new NetState(NetState.FEAILED,"划拨出错");
        }
        return new NetState(NetState.SUCCESS_CONN,"划拨成功共划拨："+count+"张");
    }
    @RequestMapping("/content_splitRechargeCards")
    public ModelAndView content_splitRechargeCards(HttpServletRequest request, String batch, // 批次
                                                   Integer curPage, // 分页
                                                   Integer status, // 充值卡状态
                                                   String pId, // 代理商
                                                   String cardnoFrom, String cardnoTo, Integer choose) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        //对数据处理
        if (pId != null && pId.equals("")) {
            pId = null;
        }
        if (cardnoFrom != null && cardnoFrom.equals("")) {
            cardnoFrom = null;
        }
        if (cardnoTo != null && cardnoTo.equals("")) {
            cardnoTo = null;
        }
        if (batch != null && batch.equals("")) {
            batch = null;
        }
        List<Rechargeablecards> rechargeablecards = null;
        List<Users> users = usersService.selectByUserName(pId);
        if (curPage == null) {
            curPage = 1;
        }
        Page page = new Page();
        List<String> parentIds = Lists.newArrayList();
        String childStr = "";
        if (parentIds.size() == 0) {
            parentIds = null;
        }
        if (users.size() > 0) {
            parentIds.add(users.get(0).getId());
        }
        //			int allNum = rechargeablecardsService.countByAllNew(sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
        //			if (allNum > 0) {
        //				page.setRecordTotal(allNum);
        //			} else {
        //				rechargeablecards = rechargeablecardsService.selectByAllNew(page, sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
        //			}
        int allNum = rechargeablecardsService.countByAllNew(status, batch, null, null, parentIds, null, null, null, cardnoFrom, cardnoTo, null, null, null);
        page.setCurrentPageNo(curPage);
        page.setRecordTotal(allNum);
        rechargeablecards = rechargeablecardsService.selectByAllNew(page, status, batch, null, null, parentIds, null, null, null, cardnoFrom, cardnoTo, null, null, null);
        request.setAttribute("list", rechargeablecards);
        request.setAttribute("batch", batch);
        request.setAttribute("curPage", curPage);
        request.setAttribute("status", status);
        request.setAttribute("cardnoFrom", cardnoFrom);
        request.setAttribute("cardnoTo", cardnoTo);
        request.setAttribute("choose", choose);
        request.setAttribute("cardnoFrom", cardnoFrom);
        request.setAttribute("totlenum", allNum);
        modelAndView.setViewName("jsp/content_splitRechargeCards");
        return modelAndView;
    }

    // 充值卡管理
    @RequestMapping("/content_chongzhikaguanliOld")
    public ModelAndView index(HttpServletRequest request) throws Exception {
        // 返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();
        RechargeablecardsExamplePage examplePage = new RechargeablecardsExamplePage();
        examplePage.pagesize = 10;
        examplePage.start = 0;
        examplePage.rows = examplePage.pagesize;// 设置首次分页
        examplePage.setOrderByClause("idNum");
        Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
        String adminUserId = (String) request.getSession().getAttribute("adminUserId");
        List<Rechargeablecards> rechargeablecards = null;
        Criteria criteria = examplePage.createCriteria();
        switch (adminUsergrade) {
            case 0:
                break;
            case 1:
                // 查询OEMID下的用户
                // 查询OEM下的商户以及OEM
                // 查询OEM下的商家
                List<String> list = usersService.selectByParentId(adminUserId);
                System.out.println("Users的数量：" + list.size());
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId));
                break;

            case 2:
                // 查询商家下的商家ID
                List<String> lists = usersService.selectByParentId(adminUserId);
                System.out.println("Users的数量：" + lists.size());
                for (String shopId : lists) {
                    // 商家下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(shopId));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId));
                break;
        }
        rechargeablecards = rechargeablecardsService.selectByExamplePage(examplePage);

        /*
         * 设置分页
         */
        int totlenum = rechargeablecardsService.countByExample(examplePage);// 页面总数
        request.setAttribute("totlenum", totlenum);// 传入session中
        request.setAttribute("curPage", 1);// 传入session中
        // 费率
        FreeroutesExample freeroutesExample = new FreeroutesExample();
        freeroutesExample.setOrderByClause("CreateTime");
        freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria().andDatastatusEqualTo(true));
        List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
        Users users = usersService.selectByPrimaryKey(adminUserId);

        if (rechargeablecards != null) {
            for (Rechargeablecards r : rechargeablecards) {
                // 设置OEM以及所属商家的账户名
                Users parent = usersService.selectByPrimaryKey(r.getParentid());
                if (parent != null && parent.getUsername() != null) {
                    r.setParentid(parent.getUsername());
                } else {
                    r.setParentid("未知");
                }

            }
            // 设置页面进行跳转
            modelAndView.setViewName("jsp/content_chongzhikaguanli");
            request.setAttribute("role", users.getRole());
            request.setAttribute("adminUserId", adminUserId);
            request.setAttribute("adminUsergrade", adminUsergrade);
            System.out.println(adminUserId);
            System.out.println(adminUsergrade);
            request.setAttribute("freeroutes", freeroutes);
            request.setAttribute("list", rechargeablecards);
            return modelAndView;
        }
        String usernamesys = (String) request.getSession().getAttribute("useracc");
        logsService.insert(CommContent.TYPE_SYS, CommContent.LOGS_READ + "充值卡资料", usernamesys, true,
                IP.getIpAddr(request));
        modelAndView.setViewName("jsp/datanotfound");
        return modelAndView;
    }

    // 充值卡管理
    @RequestMapping("/selectChongzhikaOld")
    public ModelAndView selectChongzhika(HttpServletRequest request, String id, // 卡id
                                         String cardno, // 卡号
                                         String pwd, // 卡密
                                         Integer money, // 面值
                                         String parentid, // 代理商
                                         String mobile, // 充值号码
                                         Integer status, // 充值卡状态
                                         Integer termofvalidity, // 有效期
                                         Integer probationperiod, // 使用有效期
                                         String batch, // 批次
                                         Boolean datastatus, // 冻结结果
                                         Integer curPage, // 分页
                                         String cardnoFrom, String cardnoTo) throws Exception {
        // 设置session缓存
        Integer choose = 1;
        System.out.println(datastatus);
        if (curPage == null) {
            if (request.getSession().getAttribute("curPage") != null) {
                curPage = (Integer) request.getSession().getAttribute("curPage");
            } else {
                curPage = 1;
            }
        }
        if (id == null) {
            if (request.getSession().getAttribute("id") != null) {
                id = (String) request.getSession().getAttribute("id");
            }
        }
        if (cardno == null) {
            if (request.getSession().getAttribute("cardno") != null) {
                cardno = (String) request.getSession().getAttribute("cardno");
            }
        }

        if (cardnoFrom == null) {
            if (request.getSession().getAttribute("cardnoFrom") != null) {
                cardnoFrom = (String) request.getSession().getAttribute("cardnoFrom");
            }
        }

        if (cardnoTo == null) {
            if (request.getSession().getAttribute("cardnoTo") != null) {
                cardnoTo = (String) request.getSession().getAttribute("cardnoTo");
            }
        }

        if (money == null) {
            if (request.getSession().getAttribute("money") != null) {
                money = (Integer) request.getSession().getAttribute("money");
            }
        }
        if (mobile == null) {
            if (request.getSession().getAttribute("mobile") != null) {
                mobile = (String) request.getSession().getAttribute("mobile");
            }
        }
        if (parentid == null) {
            if (request.getSession().getAttribute("parentid") != null) {
                parentid = (String) request.getSession().getAttribute("parentid");
            }
        }
        if (status == null) {
            if (request.getSession().getAttribute("status") != null) {
                status = (Integer) request.getSession().getAttribute("status");
            }
        }
        if (termofvalidity == null) {
            if (request.getSession().getAttribute("termofvalidity") != null) {
                termofvalidity = (Integer) request.getSession().getAttribute("termofvalidity");
            }
        }
        if (probationperiod == null) {
            if (request.getSession().getAttribute("probationperiod") != null) {
                probationperiod = (Integer) request.getSession().getAttribute("probationperiod");
            }
        }
        if (batch == null) {
            if (request.getSession().getAttribute("batch") != null) {
                batch = (String) request.getSession().getAttribute("batch");
            }
        }
        if (datastatus == null) {
            if (request.getSession().getAttribute("datastatus") != null) {
                datastatus = (Boolean) request.getSession().getAttribute("datastatus");
            }
        }
        // 如果choose为1 条件查询 choose为2 查询所有
        if (id != null && !id.equals("") || cardno != null && !cardno.equals("")
                || cardnoFrom != null && !cardnoFrom.equals("") && cardnoTo != null && !cardnoTo.equals("")
                || pwd != null && !pwd.equals("") || money != null || mobile != null && !mobile.equals("")
                || parentid != null && !parentid.equals("") || termofvalidity != null || probationperiod != null
                || batch != null && !batch.equals("") || datastatus != null) {
            choose = 1;
        } else {
            choose = 2;
        }
        System.out.println(cardno);
        // 返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();
        RechargeablecardsExamplePage examplePage = new RechargeablecardsExamplePage();
        examplePage.pagesize = 10;
        examplePage.start = (curPage - 1) * examplePage.pagesize;
        examplePage.rows = examplePage.pagesize;// 设置首次分页
        examplePage.setOrderByClause("CardNo");

        Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
        String adminUserId = (String) request.getSession().getAttribute("adminUserId");
        List<Rechargeablecards> rechargeablecards = null;
        Criteria criteria = examplePage.createCriteria();

        System.out.println(choose);
        // admin条件筛选
        if (adminUsergrade == 0) {
            if (id != null && !id.equals("")) {
                request.setAttribute("id", id);
                criteria.andIdEqualTo(id);
                examplePage.getOredCriteria().add(criteria);
            }
            if (cardno != null && !cardno.equals("")) {
                request.setAttribute("cardno", cardno);
                criteria.andCardnoEqualTo(cardno);
                examplePage.getOredCriteria().add(criteria);
            }
            if (cardnoFrom != null && !cardnoFrom.equals("") && cardnoTo != null && !cardnoTo.equals("")) {
                request.setAttribute("cardnoFrom", cardnoFrom);
                request.setAttribute("cardnoTo", cardnoTo);
                criteria.andCardnoBetween(cardnoFrom, cardnoTo);
                examplePage.getOredCriteria().add(criteria);
            }
            if (pwd != null && !pwd.equals("")) {
                request.setAttribute("pwd", pwd);
                criteria.andPwdEqualTo(pwd);
                examplePage.getOredCriteria().add(criteria);
            }
            if (money != null) {
                request.setAttribute("money", money);
                criteria.andMoneyEqualTo(money);
                examplePage.getOredCriteria().add(criteria);
            }
            if (mobile != null && !mobile.equals("")) {
                request.setAttribute("mobile", mobile);
                criteria.andMobileEqualTo(mobile);
                examplePage.getOredCriteria().add(criteria);
            }
            if (parentid != null && !parentid.equals("")) {
                request.setAttribute("parentid", parentid);
                criteria.andParentidEqualTo(usersService.selectByUsername(parentid).getId());
                examplePage.getOredCriteria().add(criteria);
            }
            if (termofvalidity != null) {
                request.setAttribute("termofvalidity", termofvalidity);
                criteria.andTermofvalidityEqualTo(termofvalidity);
                examplePage.getOredCriteria().add(criteria);
            }
            if (probationperiod != null) {
                request.setAttribute("probationperiod", probationperiod);
                criteria.andProbationperiodEqualTo(probationperiod);
                examplePage.getOredCriteria().add(criteria);
            }
            if (batch != null && !batch.equals("")) {
                request.setAttribute("batch", batch);
                criteria.andBatchEqualTo(batch);
                examplePage.getOredCriteria().add(criteria);
            }
            if (datastatus != null) {
                request.setAttribute("datastatus", datastatus);
                criteria.andDatastatusEqualTo(datastatus);
                examplePage.getOredCriteria().add(criteria);
            }
            //TODO admin 根据是否充值过查询
            if (status != null) {
                // 判断当前可用性
                switch (status) {
                    case 0:
                        examplePage.getOredCriteria().add(criteria.andStatusEqualTo(0));
                        break;
                    case 1:
                        examplePage.getOredCriteria().add(criteria.andStatusEqualTo(1));
                        break;
                    case 2:
                        break;
                }
            }
        }

        System.out.println(adminUsergrade);
        // oem筛选条件
        if (adminUsergrade == 1) {
            List<String> list = usersService.selectByParentId(adminUserId);
            if (id != null && !id.equals("")) {
                request.setAttribute("id", id);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andIdEqualTo(id));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andIdEqualTo(id));
            }
            if (cardno != null && !cardno.equals("")) {
                request.setAttribute("cardno", cardno);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andCardnoEqualTo(cardno));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andCardnoEqualTo(cardno));

            }
            if (cardnoFrom != null && !cardnoFrom.equals("") && cardnoTo != null && !cardnoTo.equals("")) {
                request.setAttribute("cardnoFrom", cardnoFrom);
                request.setAttribute("cardnoTo", cardnoTo);
                for (String oemId : list) {
                    // OEM下的商家

                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andCardnoBetween(cardnoFrom,
                            cardnoTo));

                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andCardnoBetween(cardnoFrom, cardnoTo));
            }
            if (pwd != null && !pwd.equals("")) {
                request.setAttribute("pwd", pwd);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andPwdEqualTo(pwd));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andPwdEqualTo(pwd));
            }
            if (money != null) {
                request.setAttribute("money", money);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andMoneyEqualTo(money));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andMoneyEqualTo(money));
            }
            if (mobile != null && !mobile.equals("")) {
                request.setAttribute("mobile", mobile);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andMobileEqualTo(mobile));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andMobileEqualTo(mobile));
            }
            if (parentid != null && !parentid.equals("")) {
                request.setAttribute("parentid", parentid);
                Users users = usersService.selectByUsername(parentid);
                System.out.println(parentid);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(users.getId()));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(users.getId()));
            }
            if (termofvalidity != null) {
                request.setAttribute("termofvalidity", termofvalidity);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId)
                            .andTermofvalidityEqualTo(termofvalidity));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andTermofvalidityEqualTo(termofvalidity));
            }
            if (probationperiod != null) {
                request.setAttribute("probationperiod", probationperiod);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId)
                            .andProbationperiodEqualTo(probationperiod));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andProbationperiodEqualTo(probationperiod));
            }
            if (batch != null && !batch.equals("")) {
                request.setAttribute("batch", batch);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andBatchEqualTo(batch));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andBatchEqualTo(batch));
            }
            if (datastatus != null) {
                request.setAttribute("datastatus", datastatus);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(
                            examplePage.createCriteria().andParentidEqualTo(oemId).andDatastatusEqualTo(datastatus));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andDatastatusEqualTo(datastatus));
            }
            if (status != null) {
                // 判断当前可用性
                switch (status) {
                    case 0:
                        for (String oemId : list) {
                            // OEM下的商家
                            examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andStatusEqualTo(0));
                        }
                        examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andStatusEqualTo(0));
                        break;
                    case 1:
                        for (String oemId : list) {
                            // OEM下的商家
                            examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andStatusEqualTo(1));
                        }
                        examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andStatusEqualTo(1));
                        break;
                    case 2:
                        break;
                }
            }
        }

        if (adminUsergrade == 2) {
            List<String> list = usersService.selectByShopId(adminUserId);
            if (id != null && !id.equals("")) {
                request.setAttribute("id", id);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andIdEqualTo(id));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andIdEqualTo(id));
            }
            if (cardno != null && !cardno.equals("")) {
                request.setAttribute("cardno", cardno);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andCardnoEqualTo(cardno));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andCardnoEqualTo(cardno));

            }
            if (cardnoFrom != null && !cardnoFrom.equals("") && cardnoTo != null && !cardnoTo.equals("")) {
                request.setAttribute("cardnoFrom", cardnoFrom);
                request.setAttribute("cardnoTo", cardnoTo);
                for (String oemId : list) {
                    // OEM下的商家

                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andCardnoBetween(cardnoFrom,
                            cardnoTo));

                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andCardnoBetween(cardnoFrom, cardnoTo));
            }
            if (pwd != null && !pwd.equals("")) {
                request.setAttribute("pwd", pwd);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andPwdEqualTo(pwd));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andPwdEqualTo(pwd));
            }
            if (money != null) {
                request.setAttribute("money", money);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andMoneyEqualTo(money));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andMoneyEqualTo(money));
            }
            if (mobile != null && !mobile.equals("")) {
                request.setAttribute("mobile", mobile);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andMobileEqualTo(mobile));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andMobileEqualTo(mobile));
            }
            if (parentid != null && !parentid.equals("")) {
                request.setAttribute("parentid", parentid);
                Users users = usersService.selectByUsername(parentid);
                System.out.println(parentid);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(users.getId()));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(users.getId()));
            }
            if (termofvalidity != null) {
                request.setAttribute("termofvalidity", termofvalidity);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId)
                            .andTermofvalidityEqualTo(termofvalidity));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andTermofvalidityEqualTo(termofvalidity));
            }
            if (probationperiod != null) {
                request.setAttribute("probationperiod", probationperiod);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId)
                            .andProbationperiodEqualTo(probationperiod));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andProbationperiodEqualTo(probationperiod));
            }
            if (batch != null && !batch.equals("")) {
                request.setAttribute("batch", batch);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andBatchEqualTo(batch));
                }
                examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andBatchEqualTo(batch));
            }
            if (datastatus != null) {
                request.setAttribute("datastatus", datastatus);
                for (String oemId : list) {
                    // OEM下的商家
                    examplePage.or(
                            examplePage.createCriteria().andParentidEqualTo(oemId).andDatastatusEqualTo(datastatus));
                }
                examplePage.getOredCriteria()
                        .add(criteria.andParentidEqualTo(adminUserId).andDatastatusEqualTo(datastatus));
            }
            if (status != null) {
                // 判断当前可用性
                switch (status) {
                    case 0:
                        for (String oemId : list) {
                            // OEM下的商家
                            examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andStatusEqualTo(0));
                        }
                        examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andStatusEqualTo(0));
                        break;
                    case 1:
                        for (String oemId : list) {
                            // OEM下的商家
                            examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId).andStatusEqualTo(1));
                        }
                        examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId).andStatusEqualTo(1));
                        break;
                    case 2:
                        break;
                }
            }
        }

        if (choose == 2) {
            switch (adminUsergrade) {
                case 0:
                    break;

                case 1:
                    // 查询OEMID下的用户
                    // 查询OEM下的商户以及OEM

                    List<String> list = usersService.selectByParentId(adminUserId);
                    System.out.println("Users的数量：" + list.size());
                    for (String oemId : list) {
                        // OEM下的商家
                        examplePage.or(examplePage.createCriteria().andParentidEqualTo(oemId));
                    }
                    examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId));
                    break;

                case 2:
                    List<String> lists = usersService.selectByShopId(adminUserId);
                    System.out.println("Users的数量：" + lists.size());
                    for (String shopId : lists) {
                        // 商家下的商家
                        examplePage.or(examplePage.createCriteria().andParentidEqualTo(shopId));
                    }
                    examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId));
                    break;
            }
        }
        // request.setAttribute("status", status);
        rechargeablecards = rechargeablecardsService.selectByExamplePage(examplePage);
        /*
         * 设置分页
         */
        int totlenum = rechargeablecardsService.countByExample(examplePage);// 页面总数
        // 费率
        FreeroutesExample freeroutesExample = new FreeroutesExample();
        freeroutesExample.setOrderByClause("CreateTime");
        freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria().andDatastatusEqualTo(true));
        List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
        request.setAttribute("totlenum", totlenum);// 总数据传入session中
        request.setAttribute("curPage", curPage);// 当前页面传入session中
        if (rechargeablecards != null) {
            for (Rechargeablecards r : rechargeablecards) {
                // 设置OEM以及所属商家的账户名
                Users parent = usersService.selectByPrimaryKey(r.getParentid());
                if (parent != null && parent.getUsername() != null) {
                    r.setParentid(parent.getUsername());
                } else {
                    r.setParentid("未知");
                }

            }

            request.setAttribute("cardnoFrom", cardnoFrom);
            request.setAttribute("cardnoTo", cardnoTo);
            request.setAttribute("batch", batch);
            request.setAttribute("freeroutes", freeroutes);// 当前页面传入session中

            // 设置页面进行跳转
            modelAndView.setViewName("jsp/content_chongzhikaguanli");
            request.setAttribute("list", rechargeablecards);

            return modelAndView;
        }
        modelAndView.setViewName("jsp/datanotfound");
        return modelAndView;
    }

    @RequestMapping("/content_chongzhikaguanli")
    public ModelAndView indexTest(HttpServletRequest request) throws Exception {
        // 返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();
        Long startTime = System.currentTimeMillis();
        Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
        String adminUserId = (String) request.getSession().getAttribute("adminUserId");
        List<Rechargeablecards> rechargeablecards = null;
        Page page = new Page();
        List<String> parentIds = Lists.newArrayList();
        String childStr = "";
        switch (adminUsergrade) {
            case 0:
                if (parentIds.size() == 0) {
                    parentIds = null;
                }
                //			int allNum = rechargeablecardsService.countByAllNew(sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
                //			if (allNum > 0) {
                //				page.setRecordTotal(allNum);
                //			} else {
                //				rechargeablecards = rechargeablecardsService.selectByAllNew(page, sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
                //			}
                int allNum = rechargeablecardsService.countByAllNew(null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                page.setCurrentPageNo(1);
                page.setRecordTotal(allNum);
                rechargeablecards = rechargeablecardsService.selectByAllNew(page, null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                break;
            default:
                if (parentIds.size() == 0) {
                    try {
                        childStr = usersService.selectAllChildByShopId(adminUserId);//查询所有下级
                    } catch (Exception e) {
//                        log.warn(e.getMessage());
                        System.out.println(e);
                    }
                    if (childStr != null && childStr.length() > 0) {
                        String[] childArr = childStr.split(",");
                        Collections.addAll(parentIds, childArr);
                    }
                    childStr = childStr == null ? adminUserId : (adminUserId + "," + childStr);
                }
                Collections.addAll(parentIds, adminUserId);
                int allNum1 = rechargeablecardsService.countByAllNew(null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                if (allNum1 > 0) {
                    page.setRecordTotal(allNum1);
                    rechargeablecards = rechargeablecardsService.selectByAllNew(page, null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                }


//		case 1:
//			page.setCurrentPageNo(1);
//			rechargeablecards = rechargeablecardsService.selectByParentid(null, adminUserId, null, null, null, null, null, null, null, null, null, null, null, null, null);
////			page.setRecordTotal(rechargeablecardsService.countByParentid(adminUserId,null, null,null, null, null, null, null, null, null, null, null, null, null));
//			page.setRecordTotal(rechargeablecards.size());
//			rechargeablecards = rechargeablecardsService.selectByParentid(page,adminUserId, null, null, null, null, null, null, null, null, null, null, null, null, null);
//			break;
//		case 2:
//			page.setCurrentPageNo(1);
//			page.setRecordTotal(rechargeablecardsService.countByShopidNotAll(adminUserId,null, null,null, null, null, null, null, null, null, null, null, null, null));
//			rechargeablecards = rechargeablecardsService.selectByShopidNotAll(page,adminUserId, null, null, null, null, null, null, null, null, null, null, null, null, null);
        }



        /*
         * 设置分页
         */
        request.setAttribute("totlenum", page.getRecordTotal()); // 分页
        request.setAttribute("curPage", page.getCurrentPageNo());// 当前页面传入session中
        // 费率
        List<Freeroutes> freeroutes = freeroutesService.selectByAll();
        Users users = usersService.selectByPrimaryKey(adminUserId);

        if (rechargeablecards != null) {
            for (Rechargeablecards r : rechargeablecards) {
                //暂时存放有效期（充值前有效期）
                r.setEndtime(Produce.plusDay(r.getTermofvalidity(), r.getCreatetime()));
                //购物金
                if (r.getType() == 6) {
                    r.setShopmoney(r.getMoney());
                } else if (r.getType() == 7) {
                    r.setShopmoney(rechargeablecardsGiftService.selectByBatch(r.getBatch()) == null ? 0 : rechargeablecardsGiftService.selectByBatch(r.getBatch()).getShopmoney());
                } else {
                    r.setShopmoney(0);
                }
            }
            Long endTime = System.currentTimeMillis();

            System.out.println("OK,用时：" + (endTime - startTime));
            // 设置页面进行跳转
            modelAndView.setViewName("jsp/content_chongzhikaguanli");
            request.setAttribute("role", users.getRole());
            request.setAttribute("adminUserId", adminUserId);
            request.setAttribute("adminUsergrade", adminUsergrade);
            request.setAttribute("freeroutes", freeroutes);
            request.setAttribute("list", rechargeablecards);
            CommExcel.rechargeablecardsList.clear();
            return modelAndView;
        }
        String usernamesys = (String) request.getSession().getAttribute("useracc");
        logsService.insert(CommContent.TYPE_SYS, CommContent.LOGS_READ + "充值卡资料", usernamesys, true,
                IP.getIpAddr(request));
        modelAndView.setViewName("jsp/datanotfound");
        return modelAndView;
    }

    @RequestMapping("/selectChongzhika")
    public ModelAndView selectChongzhikaNew(HttpServletRequest request, String id, // 卡id
                                            String cardno, // 卡号
                                            String pwd, // 卡密
                                            Integer money, // 面值
                                            String parentid, // 代理商
                                            String mobile, // 充值号码
                                            Integer status, // 充值卡状态
                                            Integer termofvalidity, // 有效期
                                            Integer probationperiod, // 使用有效期
                                            String batch, // 批次
                                            Integer datastatus, // 冻结结果
                                            Integer type,
                                            String feelroute,//费率组
                                            Integer curPage, // 分页
                                            String cardnoFrom, String cardnoTo) throws Exception {
        // 设置session缓存
        Integer choose = 1;
        if (curPage == null) {
            if (request.getSession().getAttribute("curPage") != null) {
                curPage = (Integer) request.getSession().getAttribute("curPage");
            } else {
                curPage = 1;
            }
        }
        if (id == null) {
            if (request.getSession().getAttribute("id") != null) {
                id = (String) request.getSession().getAttribute("id");
            }
        }
        if (cardno == null) {
            if (request.getSession().getAttribute("cardno") != null) {
                cardno = (String) request.getSession().getAttribute("cardno");
            }
        }

        if (cardnoFrom == null) {
            if (request.getSession().getAttribute("cardnoFrom") != null) {
                cardnoFrom = (String) request.getSession().getAttribute("cardnoFrom");
            }
        }

        if (cardnoTo == null) {
            if (request.getSession().getAttribute("cardnoTo") != null) {
                cardnoTo = (String) request.getSession().getAttribute("cardnoTo");
            }
        }

        if (money == null) {
            if (request.getSession().getAttribute("money") != null) {
                money = (Integer) request.getSession().getAttribute("money");
            }
        }
        if (mobile == null) {
            if (request.getSession().getAttribute("mobile") != null) {
                mobile = (String) request.getSession().getAttribute("mobile");
            }
        }
        if (parentid == null) {
            if (request.getSession().getAttribute("parentid") != null) {
                parentid = (String) request.getSession().getAttribute("parentid");
            }
        }
        if (status == null) {
            if (request.getSession().getAttribute("status") != null) {
                status = (Integer) request.getSession().getAttribute("status");
            }
        }
        if (termofvalidity == null) {
            if (request.getSession().getAttribute("termofvalidity") != null) {
                termofvalidity = (Integer) request.getSession().getAttribute("termofvalidity");
            }
        }
        if (probationperiod == null) {
            if (request.getSession().getAttribute("probationperiod") != null) {
                probationperiod = (Integer) request.getSession().getAttribute("probationperiod");
            }
        }
        if (batch == null) {
            if (request.getSession().getAttribute("batch") != null) {
                batch = (String) request.getSession().getAttribute("batch");
            }
        }
        if (datastatus == null) {
            if (request.getSession().getAttribute("datastatus") != null) {
                datastatus = (Integer) request.getSession().getAttribute("datastatus");
            }
        }
        // 如果choose为1 条件查询 choose为2 查询所有
        if (id != null && !id.equals("") || cardno != null && !cardno.equals("")
                || cardnoFrom != null && !cardnoFrom.equals("") && cardnoTo != null && !cardnoTo.equals("")
                || pwd != null && !pwd.equals("") || money != null || mobile != null && !mobile.equals("")
                || parentid != null && !parentid.equals("") || termofvalidity != null || probationperiod != null
                || batch != null && !batch.equals("") || datastatus != null || status != null || type != null) {
            choose = 1;
        } else {
            choose = 2;
        }
        // 返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();

        Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
        String adminUserId = (String) request.getSession().getAttribute("adminUserId");
        log.warn("[卡密管理adminUserId] 传入"+adminUserId);
        List<Rechargeablecards> rechargeablecards = null;

        String sCardno = null;
        Integer sMoney = null;// 面值
        String pId = null; // 代理商
        String sMobile = null;// 充值号码
        Integer sStatus = null;// 充值卡状态
        Integer sTermofvalidity = null; // 有效期
        Integer sProbationperiod = null;// 使用有效期
        String sBatch = null;  // 批次
        Boolean sDatastatus = null;// 冻结结果
        String sCardnoFrom = null;
        String sCardnoTo = null;
        Integer sType = null;
        String sFeelroute = null;

        if (cardno != null && !cardno.equals("")) {
            sCardno = cardno;
        }
        if (cardnoFrom != null && !cardnoFrom.equals("") && cardnoTo != null && !cardnoTo.equals("")) {
            sCardnoFrom = cardnoFrom;
            sCardnoTo = cardnoTo;
        }
        if (money != null) {
            sMoney = money;
        }
        if (mobile != null && !mobile.equals("")) {
            sMobile = mobile;
        }
        if (termofvalidity != null) {
            sTermofvalidity = termofvalidity;
        }
        if (probationperiod != null) {
            sProbationperiod = probationperiod;
        }
        if (batch != null && !batch.equals("")) {
            sBatch = batch;
        }
        if (feelroute != null && !feelroute.equals("")) {
            sFeelroute = feelroute;
        }
        if (type != null) {
            switch (type) {
                case 0:

                    break;
                case 1:

                    sType = 1;
                    break;
                case 2:

                    sType = 2;
                    break;
                case 3:

                    sType = 3;
                    break;
                case 4:

                    sType = 4;
                    break;
                case 5:

                    sType = 5;
                    break;
                case 6:
                    sType = 6;
                    break;
                case 7:
                    sType = 7;
                    break;
                case 8:
                    sType = 8;
                    break;
                case 10:

                    break;
            }
        }
        //TODO admin 根据是否充值过查询
        if (status != null) {
            // 判断当前可用性
            switch (status) {
                case 0:

                    break;
                case 1:
                    //未充值
                    sStatus = 0;
                    break;
                case 2:
                    //已充值
                    sStatus = 1;
                    break;
                case 3:

                    break;
            }
        }

        if (datastatus != null) {
            // 判断当前可用性
            switch (datastatus) {
                case 0:

                    break;
                case 1:
                    //正常
                    sDatastatus = true;
                    break;
                case 2:
                    //冻结
                    sDatastatus = false;
                    break;
                case 3:

                    break;
            }
        }
        //递归:
        List<String> parentIds = Lists.newArrayList();
        // 判断当前可用性
        if (parentid != null && !parentid.equals("")) {
            Users users = usersService.selectByUsername(parentid);
            if (users != null) {
                pId = users.getId();
                parentIds.add(pId);
            }
        }
        String maxCardNo = "";
        String minCardNo = "";
        if (sBatch != null && !sBatch.equals("")) {
            maxCardNo = rechargeablecardsService.selectMaxCards(sBatch);
            minCardNo = rechargeablecardsService.selectMinCards(sBatch);
        }


        Page page = new Page();
        page.setCurrentPageNo(curPage == null ? 1 : curPage);
        String childStr = "";
        if (choose.equals(1)) {//条件查询
            if (adminUsergrade.equals(0)) {
                if (parentid == null || parentid.equals("")) {
                    parentIds = null;
                }
                int allNum = rechargeablecardsService.countByAllNew(sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
                if (allNum > 0) {
                    page.setRecordTotal(allNum);
                }
                rechargeablecards = rechargeablecardsService.selectByAllNew(page, sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
            } else {
                if (StringUtils.isEmpty(parentid)) {
                    log.warn("[卡密管理代理商ID显示:]"+parentid);
                    log.warn("[卡密管理adminUserID数值:]"+adminUserId);
                    childStr = usersService.selectAllChildByShopId(adminUserId);//查询所有下级
                    if (childStr != null && childStr.length() > 0) {
                        String[] childArr = childStr.split(",");
                        Collections.addAll(parentIds, childArr);
                    }
                    childStr = childStr == null ? adminUserId : (adminUserId + "," + childStr);
                }
                parentIds=Arrays.asList(childStr.split(","));
                int allNum1 = rechargeablecardsService.countByAllNew(sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
                if (allNum1 > 0) {
                    page.setRecordTotal(allNum1);
                    rechargeablecards = rechargeablecardsService.selectByAllNew(page, sStatus, sBatch, sMoney, sMobile, parentIds, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
                }
            }
        }

//         if (choose == 1){
//             // admin条件筛选
//             page.setCurrentPageNo(curPage);
//             if (adminUsergrade == 0) {
//                 page.setRecordTotal(rechargeablecardsService.countByAll(sStatus, sBatch, sMoney, sMobile, pId, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute));
//                 rechargeablecards = rechargeablecardsService.selectByAll(page, sStatus, sBatch, sMoney, sMobile, pId, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
//             }
//             if (adminUsergrade == 1) {
//                 page.setRecordTotal(rechargeablecardsService.countByParentid(adminUserId, sStatus, sBatch, sMoney, sMobile, pId, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute));
//                 rechargeablecards = rechargeablecardsService.selectByParentid(page, adminUserId, sStatus, sBatch, sMoney, sMobile, pId, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
//             }
//             if (adminUsergrade == 2) {
//                 page.setRecordTotal(rechargeablecardsService.countByShopidNotAll(adminUserId, sStatus, sBatch, sMoney, sMobile, pId, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute));
//                 rechargeablecards = rechargeablecardsService.selectByShopidNotAll(page, adminUserId, sStatus, sBatch, sMoney, sMobile, pId, sCardno, sTermofvalidity, sProbationperiod, sCardnoFrom, sCardnoTo, sDatastatus, sType, sFeelroute);
//             }
//         }

        if (choose == 2) {
            switch (adminUsergrade) {
                case 0:
                    if (parentIds.size() == 0) {
                        parentIds = null;
                    }
                    int allNum = rechargeablecardsService.countByAllNew(null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                    page.setCurrentPageNo(1);
                    page.setRecordTotal(allNum);
                    rechargeablecards = rechargeablecardsService.selectByAllNew(page, null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                    break;
                default:
                    if (parentIds.size() == 0) {
                        try {
                            childStr = usersService.selectAllChildByShopId(adminUserId);//查询所有下级
                        } catch (Exception e) {
//                            log.warn(e.getMessage());
                            System.out.println(e);
                        }
                        if (childStr != null && childStr.length() > 0) {
                            String[] childArr = childStr.split(",");
                            Collections.addAll(parentIds, childArr);
                        }
                        childStr = childStr == null ? adminUserId : (adminUserId + "," + childStr);
                    }
                    Collections.addAll(parentIds, adminUserId);
                    int allNum1 = rechargeablecardsService.countByAllNew(null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                    if (allNum1 > 0) {
                        page.setRecordTotal(allNum1);
                        rechargeablecards = rechargeablecardsService.selectByAllNew(page, null, null, null, null, parentIds, null, null, null, null, null, null, null, null);
                    }
            }
        }
        /*
         * 设置分页
         */
        request.setAttribute("totlenum", page.getRecordTotal()); // 分页
        request.setAttribute("curPage", page.getCurrentPageNo());// 当前页面传入session中
        // 费率
        List<Freeroutes> freeroutes = freeroutesService.selectByAll();
        if (rechargeablecards != null) {
            for (Rechargeablecards r : rechargeablecards) {
                //暂时存放有效期（充值前有效期）
                r.setEndtime(Produce.plusDay(r.getTermofvalidity(), r.getCreatetime()));
                //购物金
                if (r.getType() == 6) {
                    r.setShopmoney(r.getMoney());
                } else if (r.getType() == 7) {
                    r.setShopmoney(rechargeablecardsGiftService.selectByBatch(r.getBatch()) == null ? 0 : rechargeablecardsGiftService.selectByBatch(r.getBatch()).getShopmoney());
                } else {
                    r.setShopmoney(0);
                }
            }

            request.setAttribute("maxCardNo", maxCardNo);
            request.setAttribute("minCardNo", minCardNo);
            request.setAttribute("cardnoFrom", cardnoFrom);
            request.setAttribute("cardnoTo", cardnoTo);
            request.setAttribute("batch", batch);
            request.setAttribute("cardno", cardno);
            request.setAttribute("money", money);
            request.setAttribute("parentid", parentid);
            request.setAttribute("mobile", mobile);
            request.setAttribute("termofvalidity", termofvalidity);
            request.setAttribute("probationperiod", probationperiod);
            request.setAttribute("status", status);
            request.setAttribute("datastatus", datastatus);
            request.setAttribute("type", type);
            request.setAttribute("freeroutes", freeroutes);
            request.setAttribute("feelroute", feelroute);// 当前页面传入session中

            // 设置页面进行跳转
            modelAndView.setViewName("jsp/content_chongzhikaguanli");
            request.setAttribute("list", rechargeablecards);
            CommExcel.rechargeablecardsList.clear();
            return modelAndView;
        }
        modelAndView.setViewName("jsp/datanotfound");
        return modelAndView;
    }

    // 卡导出
    @RequestMapping("/chongzhikaExitInfo")
    public ModelAndView chongzhikaExitInfo(HttpServletRequest request, String batch) throws Exception {
        // 设置session缓存
        if (batch == null) {
            if (request.getSession().getAttribute("batch") != null) {
                batch = (String) request.getSession().getAttribute("batch");
            }
        }
        // 返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();

        return modelAndView;
    }

    // 卡导入 读取
    @RequestMapping("/allCardsInfo")
    public void cardsInfo(HttpServletRequest request, HttpServletResponse response, String file) throws Exception {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        List<Rechargeablecards> cards = new ArrayList<Rechargeablecards>();

        cards.clear();

        Rechargeablecards card = null;
        try {
            FileReader fr = new FileReader(file);
            BufferedReader bf = new BufferedReader(fr);
            String str;
            String[] arr;
            // 按行读取字符串
            while ((str = bf.readLine()) != null) {
                card = new Rechargeablecards();
                // 接取信息
                arr = str.split(",");

                card.setCardno(arr[1]);
                card.setPwd(arr[2]);
                card.setMoney(new BigDecimal(arr[3]).intValue());
                card.setTermofvalidity(Integer.parseInt(arr[4]));
                cards.add(card);
            }

            bf.close();
            fr.close();
        } catch (IOException e) {
            out.print("读取失败");
            return;
        }

        insertCards(request, response, cards);
    }

    @RequestMapping("/insertAllCards")
    private void insertCards(HttpServletRequest request, HttpServletResponse response,
                             List<Rechargeablecards> rechargeablecards) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();
        String adminId = (String) request.getSession().getAttribute("adminUserId");

        Long startTime = System.currentTimeMillis();

        Page page = new Page();
        page.setCurrentPageNo(1);
        page.setRecordTotal(10);
        List<Rechargeablecards> cards = rechargeablecardsService.selectByAll(page, null, null, null, null, null, null, null, null,
                null, null, null, null, null);
        int lastnumber = 0;
        String num = PasswordUtils.Getnum();
        if(cards != null && cards.size() > 0) {
            Rechargeablecards r = cards.get(0);
            lastnumber = Integer.parseInt(r.getNumber());
        }

        Connection conn = null;
        PreparedStatement pstm = null;
        String repeated = "";
        int nums = 0;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(CommUrls.JDBC, CommUrls.JDBC_USER, CommUrls.JDBC_PASSWORD);
            String sql = " insert into rechargeablecards (ID, CardNo, Pwd, " + " Money, ParentID, Status, "
                    + " TermOfValidity, ProbationPeriod, FeelRoute, " + " DataStatus, Batch, CreateTime, "
                    + " UseTime, Mobile, PicPath, " + " Type, Number)values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            pstm = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            conn.setAutoCommit(false);
            //生成的卡号
            String cardno = null;
            //生成的第一张卡
            String fistCardno = null;
            //生成的最后一张卡
            String lastCardno = null;
            List<Rechargeablecards> haveCards = null;
            if(rechargeablecards != null && rechargeablecards.size() > 0) {
                for (int i = 0; i < rechargeablecards.size(); i++) {
                    haveCards = rechargeablecardsService.selectByCardNo(rechargeablecards.get(i).getCardno());
                    if(haveCards != null && haveCards.size() > 0) {
                        repeated += rechargeablecards.get(i).getCardno() + ",";
                        continue;
                    }

                    lastnumber += 1;
                    pstm.setString(1, Produce.getUUID());
                    cardno = rechargeablecards.get(i).getCardno();
                    pstm.setString(2 , cardno);
                    if(i == 1) {
                        fistCardno = cardno;
                    }
                    if(i == rechargeablecards.size()) {
                        lastCardno = cardno;
                    }
                    pstm.setString(3, rechargeablecards.get(i).getPwd());
                    pstm.setInt(4, rechargeablecards.get(i).getMoney());
                    pstm.setString(5, adminId);
                    pstm.setInt(6, 0);
                    pstm.setInt(7, rechargeablecards.get(i).getTermofvalidity());
                    pstm.setInt(8, 365);
                    pstm.setString(9, "SBD0.25");
                    pstm.setBoolean(10, true);
                    pstm.setString(11, num);
                    pstm.setDate(12, new Date(Produce.getNowDate().getTime()));
                    pstm.setDate(13, new Date(Produce.getNowDate().getTime()));
                    pstm.setString(14, null);
                    pstm.setString(15, null);
                    pstm.setInt(16, 4);
                    pstm.setString(17, String.valueOf(lastnumber));
                    nums++;
                    pstm.addBatch();
                    if ((i + 1) % 1000 == 0) {
                        pstm.executeBatch();// 每执行一次就清一次sql缓存。
                        pstm.clearBatch(); // 否则每一次是执行1000，2000，3000...条sql语句而不是每一次执行1000条
                    }

                    pstm.executeBatch();
                    conn.commit();
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                String nowTime = sdf.format(new java.util.Date());
                String usernamesys = (String) request.getSession().getAttribute("useracc");
//				Users u = usersService.selectByPrimaryKey(parentid);
                logsService.insert(CommContent.TYPE_DELET_DAORUKA, "用户：" + usernamesys + " 导入卡密,卡号从：" + fistCardno + "到" + lastCardno + ",数量：" + nums
                        + ",时间" + nowTime, usernamesys, true, IP.getIpAddr(request));
                Long endTime = System.currentTimeMillis();

                if(repeated != null && !repeated.equals("")) {
                    out.print("导入成功, 导入" + nums + "张卡成功,重复卡号已重新导出,");
                    allCardsExport(request, response, repeated, adminId);
                }else {
                    out.print("导入成功, 导入" + nums + "张卡成功");
                }
                System.out.println("导入" + nums + "张卡成功,用时：" + (endTime - startTime) + "毫秒");
            }else {
                out.print("导入失败");
                return;
            }
        } catch (Exception e) {
            out.print("导入失败，请您重试");
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            if (pstm != null) {
                try {
                    pstm.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    out.print("导入失败，请您重试");
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
        }
    }

    // 重复的卡导出
    @RequestMapping("/allCardsExport")
    public void allCardsExport(HttpServletRequest request, HttpServletResponse response, String repeated,
                               String adminId) throws Exception {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        Users user = usersService.selectByPrimaryKey(adminId);
        String file = filePath+"Txt/"+ user.getUsername() +"导入服务器重复卡.txt";
        try {
            File writeFile = new File(file);
            writeFile.createNewFile(); // 创建新文件
            BufferedWriter bw = new BufferedWriter(new FileWriter(writeFile));
            String[] cards = repeated.split(",");
            for(String card : cards) {
                bw.write(card + "\r\n"); // \r\n即为换行
            }

            bw.flush(); // 把缓存区内容压入文件
            bw.close(); // 最后记得关闭文件
        } catch (Exception e) {
            e.printStackTrace();
        }

        out.print("smms.sbdznkj.com:2018/file/Txt/"+ user.getUsername() +"导入服务器重复卡.txt");
    }

    // 卡导入excel 读取
    @RequestMapping("/excelCardsInfo")
    public void excelCardsInfo(HttpServletRequest request, HttpServletResponse response, String file) throws Exception {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        readExcel(request,response,file);

        insertExcelCards(request, response);
    }

    @RequestMapping("/insertExcelCards")
    private void insertExcelCards(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();
        String adminId = (String) request.getSession().getAttribute("adminUserId");

        Long startTime = System.currentTimeMillis();

        Page page = new Page();
        page.setCurrentPageNo(1);
        page.setRecordTotal(10);
        List<Rechargeablecards> cards = rechargeablecardsService.selectByAll(page, null, null, null, null, null, null, null, null,
                null, null, null, null, null);
        int lastnumber = 0;
        if(cards != null && cards.size() > 0) {
            Rechargeablecards r = cards.get(0);
            lastnumber = Integer.parseInt(r.getNumber());
        }

        Connection conn = null;
        PreparedStatement pstm = null;
        String repeated = "";
        int nums = 0;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(CommUrls.JDBC, CommUrls.JDBC_USER, CommUrls.JDBC_PASSWORD);
            String sql = " insert into rechargeablecards (ID, CardNo, Pwd, " + " Money, ParentID, Status, "
                    + " TermOfValidity, ProbationPeriod, FeelRoute, " + " DataStatus, Batch, CreateTime, "
                    + " UseTime, Mobile, PicPath, " + " Type, Number)values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            pstm = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            conn.setAutoCommit(false);
            //生成的卡号
            String cardno = null;
            //生成的第一张卡
            String fistCardno = null;
            //生成的最后一张卡
            String lastCardno = null;
            List<Rechargeablecards> haveCards = null;
            if(CommExcel.rechargeablecardsList != null && CommExcel.rechargeablecardsList.size() > 0) {
                for (int i = 0; i < CommExcel.rechargeablecardsList.size(); i++) {
                    haveCards = rechargeablecardsService.selectByCardNo(CommExcel.rechargeablecardsList.get(i).getCardno());
                    if(haveCards != null && haveCards.size() > 0) {
                        repeated += CommExcel.rechargeablecardsList.get(i).getCardno() + ",";
                        continue;
                    }

                    lastnumber += 1;
                    pstm.setString(1, Produce.getUUID());
                    cardno = CommExcel.rechargeablecardsList.get(i).getCardno();
                    pstm.setString(2 , cardno);
                    if(i == 1) {
                        fistCardno = CommExcel.rechargeablecardsList.get(i).getCardno();
                    }
                    if(i == CommExcel.rechargeablecardsList.size()) {
                        lastCardno = CommExcel.rechargeablecardsList.get(i).getCardno();
                    }
                    pstm.setString(3, CommExcel.rechargeablecardsList.get(i).getPwd());
                    pstm.setInt(4, CommExcel.rechargeablecardsList.get(i).getMoney());
                    pstm.setString(5, adminId);
                    pstm.setInt(6, CommExcel.rechargeablecardsList.get(i).getStatus());
                    pstm.setInt(7, CommExcel.rechargeablecardsList.get(i).getTermofvalidity());
                    pstm.setInt(8, 90);
                    pstm.setString(9, "SBD0.25");
                    pstm.setInt(10, 1);
                    pstm.setString(11, CommExcel.rechargeablecardsList.get(i).getBatch());
                    pstm.setString(12, new SimpleDateFormat("yyyy-MM-dd").format(CommExcel.rechargeablecardsList.get(i).getCreatetime()));
                    pstm.setString(13, new SimpleDateFormat("yyyy-MM-dd").format(CommExcel.rechargeablecardsList.get(i).getCreatetime()));
                    pstm.setString(14, null);
                    pstm.setString(15, null);
                    pstm.setInt(16, CommExcel.rechargeablecardsList.get(i).getType());
                    pstm.setString(17, String.valueOf(lastnumber));
                    nums++;
                    pstm.addBatch();
                    if ((i + 1) % 1000 == 0) {
                        pstm.executeBatch();// 每执行一次就清一次sql缓存。
                        pstm.clearBatch(); // 否则每一次是执行1000，2000，3000...条sql语句而不是每一次执行1000条
                    }

                    pstm.executeBatch();
                    conn.commit();
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                String nowTime = sdf.format(new java.util.Date());
                String usernamesys = (String) request.getSession().getAttribute("useracc");
//				Users u = usersService.selectByPrimaryKey(parentid);
                logsService.insert(CommContent.TYPE_DELET_DAORUKA, "用户：" + usernamesys + "导入卡密,卡号从：" + fistCardno + "到" + lastCardno + ",数量：" + nums
                        + ",时间" + nowTime, usernamesys, true, IP.getIpAddr(request));
                Long endTime = System.currentTimeMillis();

                if(repeated != null && !repeated.equals("")) {
                    out.print("导入成功, 导入" + nums + "张卡成功,重复卡号已重新导出,");
                    allCardsExport(request, response, repeated, adminId);
                }else {
                    out.print("导入成功, 导入" + nums + "张卡成功");
                }
                System.out.println("导入" + nums + "张卡成功,用时：" + (endTime - startTime) + "毫秒");
            }else {
                out.print("导入失败");
                return;
            }
        } catch (Exception e) {
            out.print("导入失败，请您重试");
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            if (pstm != null) {
                try {
                    pstm.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    out.print("导入失败，请您重试");
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
        }
    }

    public void readExcel(HttpServletRequest request, HttpServletResponse response, String file) throws Exception{

        PrintWriter out = response.getWriter();
        if (file == null || CommExcel.EMPTY.equals(file)) {
            out.println("请传入正确的Excel文件");
            return;
        } else {
            String postfix = getPostfix(file);
            if (!CommExcel.EMPTY.equals(postfix)) {
                if (CommExcel.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
                    readXls(request,response,file);
                } else if (CommExcel.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
                    readXlsx(request,response,file);
                }
            } else {
                System.out.println(file + CommExcel.NOT_EXCEL_FILE);
            }
        }
    }

    /**
     * 读取 Excel 2010
     * @param file
     * @return
     * @throws IOException
     */
    public void readXlsx(HttpServletRequest request, HttpServletResponse response, String file) throws Exception {
        System.out.println(CommExcel.PROCESSING + file);
        InputStream is = new FileInputStream(file);
        @SuppressWarnings("resource")
        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
        Rechargeablecards rechargeablecards = null;
        // 读取表格
        for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
            XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
            if (xssfSheet == null) {
                continue;
            }
            // 读取行
            for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
                XSSFRow xssfRow = xssfSheet.getRow(rowNum);
                if (xssfRow != null) {
                    rechargeablecards = new Rechargeablecards();
                    XSSFCell cardNo = xssfRow.getCell(1);
                    XSSFCell pwd = xssfRow.getCell(2);
                    XSSFCell money = xssfRow.getCell(3);
                    XSSFCell termofvalidity = xssfRow.getCell(4);
                    XSSFCell batch = xssfRow.getCell(5);
                    XSSFCell createtime = xssfRow.getCell(6);
                    XSSFCell endtime = xssfRow.getCell(7);
                    XSSFCell cardType = xssfRow.getCell(8);

                    rechargeablecards.setCardno(getXValue(cardNo));
                    rechargeablecards.setPwd(getXValue(pwd));
                    rechargeablecards.setMoney(Integer.valueOf(getXValue(money).substring(0, getXValue(money).length()-1)));
                    rechargeablecards.setStatus(0);
                    rechargeablecards.setTermofvalidity(Integer.valueOf(getXValue(termofvalidity).substring(0, getXValue(money).length()-1).trim()));
                    rechargeablecards.setBatch(getXValue(batch));
                    rechargeablecards.setCreatetime(new SimpleDateFormat("yyyy-MM-dd").parse(getXValue(createtime)));
                    switch (getXValue(cardType)){
                        case "月卡" :
                            rechargeablecards.setType(1);
                            break;
                        case "季卡" :
                            rechargeablecards.setType(2);
                            break;
                        case "年卡" :
                            rechargeablecards.setType(3);
                            break;
                        case "面值卡" :
                            rechargeablecards.setType(4);
                            break;
                        case "购物卡" :
                            rechargeablecards.setType(5);
                            break;
                    }

                    CommExcel.rechargeablecardsList.add(rechargeablecards);
                }
            }
        }
    }

    /**
     * 读取 Excel 2003-2007
     * @param file
     * @return
     * @throws IOException
     * @throws ParseException
     */
    public void readXls(HttpServletRequest request, HttpServletResponse response, String file) throws IOException, ParseException {
        System.out.println(CommExcel.PROCESSING + file);
        PrintWriter out = response.getWriter();
        InputStream is = new FileInputStream(file);
        @SuppressWarnings("resource")
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
        Rechargeablecards rechargeablecards = null;
        // 读取表格
        for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
            HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
            if (hssfSheet == null) {
                continue;
            }
            // 读取行
            for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                HSSFRow hssfRow = hssfSheet.getRow(rowNum);
                if (hssfRow != null) {
                    rechargeablecards = new Rechargeablecards();
                    HSSFCell cardNo = hssfRow.getCell(1);
                    HSSFCell pwd = hssfRow.getCell(2);
                    HSSFCell money = hssfRow.getCell(3);
                    HSSFCell termofvalidity = hssfRow.getCell(4);
                    HSSFCell batch = hssfRow.getCell(5);
                    HSSFCell createtime = hssfRow.getCell(6);
                    HSSFCell endtime = hssfRow.getCell(7);
                    HSSFCell cardType = hssfRow.getCell(8);

                    rechargeablecards.setCardno(getHValue(cardNo));
                    rechargeablecards.setPwd(getHValue(pwd));
                    rechargeablecards.setMoney(Integer.valueOf(getHValue(money).substring(0, getHValue(money).length()-2).trim()));
                    rechargeablecards.setStatus(0);
                    rechargeablecards.setTermofvalidity(Integer.valueOf(getHValue(termofvalidity).substring(0, getHValue(termofvalidity).length()-1).trim()));
                    rechargeablecards.setBatch(getHValue(batch));
                    rechargeablecards.setCreatetime(new SimpleDateFormat("yyyy-MM-dd").parse(getHValue(createtime)));
                    switch (getHValue(cardType)){
                        case "月卡" :
                            rechargeablecards.setType(1);
                            break;
                        case "季卡" :
                            rechargeablecards.setType(2);
                            break;
                        case "年卡" :
                            rechargeablecards.setType(3);
                            break;
                        case "面值卡" :
                            rechargeablecards.setType(4);
                            break;
                        case "购物卡" :
                            rechargeablecards.setType(5);
                            break;
                    }

                    CommExcel.rechargeablecardsList.add(rechargeablecards);
                }
            }
        }
    }

    //Excal 2007-2010 取值
    @SuppressWarnings({ "static-access", "deprecation" })
    private String getXValue(XSSFCell xssfRow) {
        if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
            return String.valueOf(xssfRow.getBooleanCellValue());
        } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
            return String.valueOf(xssfRow.getNumericCellValue());
        } else {
            return String.valueOf(xssfRow.getStringCellValue());
        }
    }

    //Excal 2003 取值
    @SuppressWarnings({ "static-access", "deprecation" })
    private String getHValue(HSSFCell hssfCell) {
        if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(hssfCell.getBooleanCellValue());
        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
            return String.valueOf(hssfCell.getNumericCellValue());
        } else {
            return String.valueOf(hssfCell.getStringCellValue());
        }
    }


    //判断Excel 2003 或者2007-2010
    public static String getPostfix(String file) {
        if (file == null || CommExcel.EMPTY.equals(file)) {
            return CommExcel.EMPTY;
        }
        if (file.contains(CommExcel.POINT)) {
            return file.substring(file.lastIndexOf(CommExcel.POINT) + 1);
        }
        return CommExcel.EMPTY;
    }
}
